<?php
class ViewController extends Yaf\Controller_Abstract{

//    public function init(){
//        Yaf\Dispatcher::getInstance()->disableView();
//    }

    public function testAction(){
//        $this->getView()->assign('title','今日份');
//        $this->getView()->assign('content','今日份----');
//        $this->getView()->assign('sname','good');

////        echo $arr['title'];
//        $one = array('title'=>'blog','name'=>'shixinke','diu'=>'asd');
//        var_dump($one);
//        echo '<br/>';
//         $this->getView()->assign($one);
//          header("location:/test.phtml");
//        可以用display，同样也可以用render，两个方法的意思都是渲染视图，区别是display是渲染之后直接输出
//        结果，render是渲染后返回结果
//            $user = UsersModel::find(1);

//        $arrs = UsersModel::orderBy('created_at','desc')->take(2)->get()->toArray();
////        var_dump($arrs);
//        $arr1 = $arrs[0];
//        echo $arr1['username'];
//        $this->getView()->display($arr1);
//        echo '<br/>';
//        $arr1 ='';
//        foreach($arrs as $key => $value){
//            echo "{$key}==>{$value}<br>";
//        }
//        $this->getView()->assign($arrs);

        //     获取id，title，content，tags，updated_at,
        $arrs = ArticleModel::orderBy('created_at','desc')->take(2)->get()->toArray();
//        var_dump($arrs);
        $arr1 = $arrs[0];
        $user = ArticleTagsModel::where('aId','=',$arr1['aId'])->select('tid')->get();
        echo $user;
//        var_dump($user);
        echo count($user);
        if (count($user)>0){
            $userj = json_decode($user,true);
            echo '<br/>';echo '<br/>';
            echo count($user);
            $tid1 = $userj[0]['tid'];
            $tid2 = $userj[1]['tid'];
            echo '<br/>'.$tid1.$tid2;
            $user1 = TagsModel::where('tid','=',$tid1)->select('tag')->get();
            $user2 = TagsModel::where('tid','=',$tid2)->select('tag')->get();
            $userj1 = json_decode($user1,true);
            echo '<br/>';
            echo '<br/>';
            echo $userj1[0]['tag'];
            $userj2 = json_decode($user2,true);
            echo $userj2[0]['tag'];
        }
//        echo '<br/>';
//        $newArr = array_values($arr1);
//        print_r(array_values($arr1));
//        echo '<br/>';
//         echo $newArr[1];
//        echo '<br/>';
//        echo '<br/>';
//        echo '<br/>';
//        $arr2 =$arrs[1];
//        $id1 = $arr1['aId'];
//        echo 'id是'.$id1;
//        $title1 = $arr1['title'];
//        echo $title1;
//        $content1 = $arr1['content'];
//        echo $content1;
//        $tags1 = $arr1['tags'];
//        $updated_at1 = $arr1['updated_at'];
//        $arrays = array('title1'=>$title1,'id1'=>$id1,'content1'=>$content1,'tags1'=>$tags1,'updated_at1'=>$updated_at1);
//        $this->getView()->assign($arr2);
//        $this->getView()->assign($arrays);
//        echo $arrays['id'];
    }
    public function test2Action(){
        $user = UsersModel::where('Id','=','1')->select('username','sex','tel','email','introduce')->get();
        if (count($user)>0){
            $u = json_decode($user,true);
            $username = $u[0]['username'];
            echo $username;
            $sex = $u[0]['sex'];

            $tel = $u[0]['tel'];
            $email = $u[0]['email'];
            $introduce = $u[0]['introduce'];
            $this->getView()->assign('username',$username);
            $this->getView()->assign('sex',$sex);
            $this->getView()->assign('tel',$tel);
            $this->getView()->assign('email',$email);
            $this->getView()->assign('introduce',$introduce);

        }
    }
}